from django.db import models


# 类目模型类
class Category(models.Model):
    name = models.CharField(max_length=40)
    superior = models.IntegerField(null=True)
    status = models.IntegerField(default=0)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'category'


# 栏目模型类
class Column(models.Model):
    name = models.CharField(max_length=40)
    status = models.IntegerField(default=0)
    priority = models.IntegerField(default=100)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'column'


# 商品模型类
class Merchandise(models.Model):
    title = models.TextField()
    subtitle = models.TextField()
    cover_img = models.TextField()
    status = models.IntegerField(default=0)
    priority = models.IntegerField(default=100)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    column = models.ForeignKey(Column, on_delete=models.CASCADE, null=True)

    class Meta:
        db_table = 'merchandise'


class MerchandiseOptions(models.Model):
    option_name = models.CharField(max_length=40)
    options = models.TextField()
    price = models.FloatField(null=True)
    inventory = models.IntegerField(null=True)
    img = models.TextField(null=True)
    status = models.IntegerField(default=0)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)
    merchandise = models.ForeignKey(Merchandise, on_delete=models.CASCADE)

    class Meta:
        db_table = 'merchandise_options'


class MerchandiseImg(models.Model):
    src = models.TextField()
    type = models.IntegerField()
    status = models.IntegerField(default=0)
    priority = models.IntegerField(default=100)
    merchandise = models.ForeignKey(Merchandise, on_delete=models.CASCADE)

    class Meta:
        db_table = 'merchandise_img'
